package com.qianchang.microfinance.view.membercentre;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.qianchang.microfinance.R;
import com.qianchang.microfinance.bean.MemberLeverListBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 电脑 on 2018/1/19.
 */

public class MemberCentreAdapter extends BaseAdapter{

    private Context mContext;
    private LayoutInflater inflater;
    private List<MemberLeverListBean> listMember;


    public MemberCentreAdapter(Context context){
        this.mContext = context;
        inflater = LayoutInflater.from(context);
        listMember = new ArrayList<>();
    }

    public void setMemberLeveData(List<MemberLeverListBean> mlistMember){
        if(mlistMember != null){
            listMember = mlistMember;
        }
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        if(listMember != null && listMember.size() > 0){
            return listMember.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return listMember.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {

        Holder holder = null;
        if(view == null){
            holder = new Holder();
            view = inflater.inflate(R.layout.item_membercentre_layout,null);
            holder.imgLeve = (ImageView) view.findViewById(R.id.img_leve_id);
            holder.tvExplanin = (TextView) view.findViewById(R.id.tv_explain_id);
            holder.goldText = (TextView) view.findViewById(R.id.tv_gold_id);
            view.setTag(holder);
        }else{
            holder = (Holder) view.getTag();
        }

        MemberLeverListBean memberLeverListBean = listMember.get(position);
        String url = memberLeverListBean.getUrlMember();
        String expl = memberLeverListBean.getExplain();
        holder.tvExplanin.setText(expl);
        holder.goldText.setText(expl);
        holder.goldText.setText(memberLeverListBean.getGold());

        Glide.with(mContext).load(url).error(R.drawable.btn_head).into(holder.imgLeve);


        return view;
    }


    private class Holder{
        private ImageView imgLeve;
        private TextView tvExplanin;
        private TextView goldText;

    }


}
